#ifndef DETECT_H
#define DETECT_H
/*
  Feature detection for NHTTP, to force a given feature to be off,
  define it as 0, to force it to be on, define as 1. To force runtime
  detection (only works for those features in sysconf(3)). In some
  cases, forcing runtime detection allows it to be configured at
  runtime.

  Note that this is only intended to be compliant to SUSv3, support for
  other standards may be added later.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

//These two will be ignored by anything not BSD or GNU
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif

#include <stdarg.h>
#include <unistd.h>
#include <stdbool.h>

void detect_init();

#if !defined _POSIX_VERSION || _POSIX_VERSION < 200112L
#warning This system does not support Single Unix Specification v3 or greater
#endif

#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
#warning Either your compiler does not support C99 or you are not building in C99 mode!
#endif

#ifndef NH_THREADS //PThreads, an option in SUSv3
#if _POSIX_THREADS == 0
#if _POSIX_READER_WRITER_LOCKS < 0
#warning Your system is not SUSv3 compliant, message queues might not work.
#warning In the mean time, you can define NH_THREADS=-1
#endif
#define NH_THREADS 0
#elif _POSIX_THREADS > 0
#if _POSIX_READER_WRITER_LOCKS <= 0
#warning Your system is not SUSv3 compliant, message queues might not work.
#warning In the mean time, you can define NH_THREADS=-1
#endif
#define NH_THREADS 1
#else
#define NH_THREADS -1
#endif
#endif

#if NH_THREADS == 0
extern bool NHD_THREADS;
#endif

#ifndef NH_SYSLOG //syslog(3) part of the XOPEN option in SUSv3
#if _XOPEN_UNIX == 0
#define NH_SYSLOG 0
#elif _XOPEN_UNIX > 0
#define NH_SYSLOG 1
#else
#define NH_SYSLOG -1
#endif
#endif

#if NH_SYSLOG == 0
extern bool NHD_SYSLOG;
#endif

#ifndef NH_ASPRINTF //asprintf(3) a GNU extension, either defined or not
#if defined __BSD__ || defined __GNUC__
#define NH_ASPRINTF 1
#endif
#elif NH_ASPRINTF == 0
#undef NH_ASPRINTF
#endif

#ifndef NH_VSYSLOG //vsyslog(3) a GNU extension, either defined or not
#if defined __BSD__ || defined __GNUC__
#define NH_VSYSLOG
#endif
#elif NH_VSYSLOG == 0
#undef NH_VSYSLOG
#endif

#ifndef NH_PMQ //POSIX Message Queues, an option in SUSv3
#if _POSIX_MESSAGE_PASSING == 0
#define NH_PMQ 0
#elif _POSIX_MESSAGE_PASSING > 0
#define NH_PMQ 1
#else
#define NH_PMQ -1
#endif
#endif

#if NH_PMQ == 0
extern bool NHD_PMQ;
#endif

#ifndef NH_XMQ //XSI Message Queues, part of the XOPEN option in SUSv3
#if _XOPEN_UNIX == 0
#define NH_XMQ 0
#elif _XOPEN_UNIX > 0
#define NH_XMQ 1
#else
#define NH_XMQ -1
#endif
#endif

#if NH_XMQ == 0
extern bool NHD_XMQ;
#endif

#ifndef NH_TIMEOUTS //POSIX Timeouts Option
#if _POSIX_TIMEOUTS == 0
#define NH_TIMEOUTS 0
#elif _POSIX_TIMEOUTS > 0
#define NH_TIMEOUTS 1
#else
#define NH_TIMEOUTS -1
#endif
#endif

#if NH_TIMEOUTS == 0
extern bool NHD_TIMEOUTS;
#endif

#ifndef NH_ASPRINTF
#define NH_ASPRINTF_BUF 256
int asprintf(char** strp, const char* fmt, ...);
int vasprintf(char** strp, const char* fmt, va_list ap);
#endif
#endif
